home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libk.lha / Lib / KRB / GET_CRED.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-01  |  2.0 KB  |  64 lines

  1. /*
  2.  * $Source: /mit/kerberos/src/lib/krb/RCS/get_cred.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
  6.  * of Technology.
  7.  *
  8.  * For copying and distribution information, please see the file
  9.  * <mit-copyright.h>.
  10.  */
  11.  
  12. #ifndef lint
  13. static char *rcsid_get_cred_c =
  14. "$Header: get_cred.c,v 4.10 89/05/31 17:46:22 jtkohl Exp $";
  15. #endif /* lint */
  16.  
  17. #include <mit_copy.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <krb.h>
  21.  
  22. /*
  23.  * krb_get_cred takes a service name, instance, and realm, and a
  24.  * structure of type CREDENTIALS to be filled in with ticket
  25.  * information.  It then searches the ticket file for the appropriate
  26.  * ticket and fills in the structure with the corresponding
  27.  * information from the file.  If successful, it returns KSUCCESS.
  28.  * On failure it returns a Kerberos error code.
  29.  */
  30.  
  31. krb_get_cred(service,instance,realm,c)
  32.     char *service;              /* Service name */
  33.     char *instance;             /* Instance */
  34.     char *realm;                /* Auth domain */
  35.     CREDENTIALS *c;             /* Credentials struct */
  36. {
  37.     int tf_status;              /* return value of tf function calls */
  38.  
  39.     /* Open ticket file and lock it for shared reading */
  40.     if ((tf_status = tf_init(TKT_FILE, R_TKT_FIL)) != KSUCCESS)
  41.     return(tf_status);
  42.  
  43.     /* Copy principal's name and instance into the CREDENTIALS struc c */
  44.  
  45.     if ( (tf_status = tf_get_pname(c->pname)) != KSUCCESS ||
  46.          (tf_status = tf_get_pinst(c->pinst)) != KSUCCESS )
  47.     return (tf_status);
  48.  
  49.     /* Search for requested service credentials and copy into c */
  50.        
  51.     while ((tf_status = tf_get_cred(c)) == KSUCCESS) {
  52.         /* Is this the right ticket? */
  53.         if ((strcmp(c->service,service) == 0) &&
  54.            (strcmp(c->instance,instance) == 0) &&
  55.            (strcmp(c->realm,realm) == 0))
  56.            break;
  57.     }
  58.     (void) tf_close();
  59.  
  60.     if (tf_status == EOF)
  61.     return (GC_NOTKT);
  62.     return(tf_status);
  63. }
  64.